#!/usr/bin/python
import os
import sys

lib_trans = '/home/xyu40/Documents/courses/CS6241/llvm/llvm-3.0.src/Release/lib/ABC.so'

util = sys.argv[1]
inp = sys.argv[2]
outp = sys.argv[3]
args = ' '.join(opt for opt in sys.argv[4:])

def gen_cmd(util, inp, outp, args):
    if util == 'clang':
        return 'clang -O0 -emit-llvm %s %s -c -o %s' %(args, inp, outp)
    elif util == 'opt':
        #return 'opt -load %s %s < %s > %s -time-passes' %(lib_trans, args, inp, outp)
        return 'opt -load %s %s < %s > %s' %(lib_trans, args, inp, outp)
    elif util == 'dist':
        return 'llvm-dis < %s > %s' %(inp, outp)
    elif util == 'ld':
        return 'llvm-ld %s -o %s' %(inp, outp)

print gen_cmd(util, inp, outp, args)
sys.stdout.flush()
os.system(gen_cmd(util, inp, outp, args))
